package com.park.web.controller.user;

import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.park.client.model.article.ArticleCollectModel;
import com.park.client.model.article.ArticleModel;
import com.park.client.service.article.ArticleCollectService;
import com.park.common.util.Page;
import com.park.common.util.PageData;
import com.park.common.util.QueryParams;
import com.park.web.controller.BaseController;
import com.park.web.util.SessionUtil;

@Controller
@RequestMapping("/user/collect")
public class UserCollectController extends BaseController{
	
	@Autowired
	private ArticleCollectService collectService;
	
	/**
	 * 显示我收藏的文章
	 */
	@RequestMapping("articleCollectList")
	@ResponseBody
	public PageData<ArticleModel> articleCollectList(QueryParams queryParams,ArticleCollectModel articleCollect,HttpSession session){
		PageData<ArticleModel> pageData = new PageData<>();
		articleCollect.setCreater(SessionUtil.getUserID(session));	
		Integer total = collectService.selectCollectTotal(articleCollect);
		Page page = new Page(queryParams.getOffset(),total,queryParams.getLimit());
		articleCollect.setStartPos(page.getStartPos());
		articleCollect.setPageSize(page.getPageSize());
		List<ArticleModel> listArticles = collectService.selectCollectPagination(articleCollect);
		pageData.setTotal(total);
		pageData.setRows(listArticles);
		return pageData;
	}
	
	
}
